﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using OOS.Application.Dish.Dtos;
using OOS.Application.Dish.Services.Interfaces;
using OOS.Application.Dish.Vos;
using OOS.Core.Dish;
using OOS.Core.RelyOn;

namespace OOS.Application.Dish
{
    /// <summary>
    /// 菜品管理
    /// </summary>
    [Route("[Controller]")]
    public class DishBasicAppService:IDynamicApiController
    {
        private readonly IDishBasicService _dishBasicService;

        public DishBasicAppService(IDishBasicService dishBasicService)
        {
            _dishBasicService = dishBasicService;
        }

        /// <summary>
        /// 添加菜品
        /// </summary>
        /// <param name="dishBasic"></param>
        /// <returns></returns>
        [HttpPost]
        public Boolean AddDishBasic(DishBasic dishBasic)
        {
            return _dishBasicService.InsertDishBasic(dishBasic);
        }

        /// <summary>
        /// 根据id查询菜品详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public DishBasicDto GetDishBasic(int id) { 
            return _dishBasicService.SelectDishById(id);
        }

        /// <summary>
        /// 根据条件(菜品名称模糊查询，菜品状态精确查询，菜品分类精确查询)分页查询菜品列表
        /// </summary>
        /// <param name="searchDishVo"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public PageResponseDto<List<DishBasicDto>> GetDishList([FromQuery]SearchDishVo searchDishVo,int pageIndex,int pageSize)
        {
            DishBasic dishBasic = searchDishVo.Adapt<DishBasic>();
            return _dishBasicService.SelectPageByConditions(dishBasic, pageIndex, pageSize);
        }

        /// <summary>
        /// 根据id修改菜品信息
        /// </summary>
        /// <param name="dishBasic"></param>
        /// <returns></returns>
        [HttpPut]
        public Boolean UpdateDishBasic(DishBasic dishBasic)
        {
            return _dishBasicService.UpdateDishBasicById(dishBasic);
        }

        /// <summary>
        /// 根据id删除菜品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public Boolean DeleteDishBasic(int id)
        {
            return _dishBasicService.DeleteDishBasicById(id);
        }

        /// <summary>
        /// 根据id修改菜品状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public Boolean UpdateStatus(int id)
        {
            return _dishBasicService.UpdateStatusById(id);
        }

        /// <summary>
        /// 批量修改菜品状态
        /// </summary>
        /// <param name="dishSelection"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpPut]
        public Boolean UpdateStatusList([FromBody]int[] dishSelection, int type)
        {
            return _dishBasicService.UpdateStatusByIds(dishSelection, type);
        }

        /// <summary>
        /// 批量删除菜品
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public Boolean DeleteDishList([FromBody] int[] ids)
        {
            return _dishBasicService.DeleteDishBasicByIds(ids);
        }

        /// <summary>
        /// 获取不同分类下菜品数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<DishByCategory> GetCategoryDishList()
        {
            return _dishBasicService.SelectDishListByCategory();
        }
    }
}
